package com.neo.consumer;

import com.neo.config.DelayedQueueConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @ClassName: DelayedQueueConsumer
 * @Title: springboot-rabbitmq
 * @Package: com.neo.consumer
 * @Description:
 * @Author: Kisen
 * @Date: 2021/9/26 21:23
 */
@Slf4j
@Component
public class DelayedQueueConsumer {

    @RabbitListener(queues = DelayedQueueConfig.DELAYED_QUEUE_NAME)
    public void receiveDelayedQueue(Message message) throws UnsupportedEncodingException {
        String msg = new String(message.getBody(), "UTF-8");
        String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        log.info("当前时间：{}，收到延时队列的消息：{}", currentTime, msg);
    }
}
